    /* global FormData */
    /* global getCookie */
    /* global template */
    /* global timeToTimestamp */
    var imgList = {};
    var list = [];
    var imgPath = '';
    var orderDetail = '';
     initData();
     /* global orderIds*/
     /* global getCookie*/
     /* global template*/
     function initData(){
         $.get('/antique/api/mallOrder/query', { id:orderIds,token:getCookie('token') }, function (result) {
            if (result.code == 0){
                orderDetail = result.data;
                $("#maxMoney").html('您最高可以退款的金额为'+ result.data.payMoney);
            }
         });
     }

    function delImg(img){
        var allImg = $("#showImages").val();
        if (img && allImg){
            var imgPath2 = '';
            var imgs = allImg.split(',');
             list = [];
             imgList = {};
            for (var i = 0; i < imgs.length; i++) {
                if (imgs[i] != img) {
                    var a = {};
                    a.path = imgs[i] ;
                    list.push(a);
                    imgPath2 = imgPath2 + imgs[i] +  ","  ;
                }
            }

            imgPath = imgPath2;
            imgList.list = list;
            imgList.imgPath = imgPath2.substring(0, imgPath2.length - 1);
            var html = template ('pho', imgList);
            document.getElementById('uploaderFiles').innerHTML = html;
        }
        
    }

    $("#uploaderInput").on("change", function(e) {
        var file = e.target.files[0];
        /* global handlePic*/
        handlePic(file,2160,function(res){
            if (res.code == 0){
                var a = {};
                a.path = res.data.path;
                imgPath = imgPath + res.data.path + "," ;
                list.push(a);
                imgList.list = list;
                imgList.imgPath = imgPath.substring(0, imgPath.length - 1);
                var html = template ('pho', imgList);
                document.getElementById('uploaderFiles').innerHTML = html;
            } else {
                $.toast(res.message, "cancel");
            }
        });
        
    });
    $("#refundReason").keyup(function() {
        var value = $.trim(this.value);
        var descLength = $.trim(this.value).length;
        if (descLength <= 200) { 
            $("#descNumber").html(descLength);
        } else {
            $("#refundReason").val(value.substring(0,200));
        }
    });
    

    function puilcPro(state){
        var id = $("#orderId").val();
        var refundType = $('input[name="refundType"]:checked').val();
        var refundMoney = $("#refundMoney").val();
        var refundReason = $("#refundReason").val();
        var showImages = $("#showImages").val();
        
        if (refundType == ''){
            $.toast("类型不能为空", "cancel");
            return;
        }
        if (refundMoney == ''){
            $.toast("退款金额不能为空", "cancel");
            return;
        }
        if (refundReason == ''){
            $.toast("退款理由不能为空", "cancel");
            return;
        }
        // if (typeof returnImage == 'undefined' || returnImage == ''){
        //     $.toast("请上传图片", "cancel");
        //     return;
        // }

        var params = {};
        params.id = id;
        params.refundType = refundType;
        params.refundMoney = refundMoney;
        params.refundReason = refundReason;
        params.returnImage = showImages;
        params.token = getCookie('token');
        if (orderDetail && orderDetail.state ==31) {//31 申请退款中 可以修改退款信息
            update(params);
        } else {
            add(params);
        }
        
    } 
    function add(params){
        $.ajax({
            type:'POST',
            url:"/antique/api/mallOrder/user/order_refund_apply",
            data: params,
            dataType:"json",
            success:function(res){
                if (res.code == 0){
                    $.toast("成功");
                    if(isMiniProgram()){
                        wx.miniProgram.navigateBack();
                    } else {
                        goPreUrl();
                    }
                 } else {
                    $.toast(res.message, "cancel");
                }                
            }
        });
    }
    function update(params){
        $.ajax({
            type:'POST',
            url:"/antique/api/mallOrder/user/order_refund_modify",
            data: params,
            dataType:"json",
            success:function(res){
                if (res.code == 0){
                    $.toast("成功");
                    if(isMiniProgram()){
                        wx.miniProgram.navigateBack();
                    } else {
                        goPreUrl();
                    }
                 } else {
                    $.toast(res.message, "cancel");
                }                
            }
        });
    }

    

